![]() |
PATH![]() |
The callback routine, callback routine parameter block, and callback notification request functions used for device notification are listed in this section.
The device notification mechanism is used to inform clients when devices are added and removed from the USB. Clients register for notification services using the USBInstallDeviceNotification function and can request all notifications or a specific notification type. Whenever a device or interface is added or removed from the bus, all registered clients are called back with the information about the device or interface.
Clients that register for notifications must be sure to un-register with the USBRemoveDeviceNotification function before their code fragment is unloaded.
The callback routine is always called at task time, and may allocate memory, make toolbox calls, or perform other system maintenance operations.
The device notification callback routine declaration is defined as:
typedef void (USBDeviceNotificationCallbackProc)
(USBDeviceNotificationParameterBlockPtr
pb);
typedef USBDeviceNotificationCallbackProc
*USBDeviceNotificationCallbackProcPtr;
The parameter block for the device notification callback routine is defined as:
/* Device Notification Parameter Block */
struct USBDeviceNotificationParameterBlock
{
UInt16 pbLength;
UInt16 pbVersion;
USBNotificationType usbDeviceNotification;
UInt8 reserved1;
USBDeviceRef usbDeviceRef;
UInt16 usbClass;
UInt16 usbSubClass;
UInt16 usbProtocol;
UInt16 usbVendor;
UInt16 usbProduct;
OSStatus result;
UInt32 token;
USBDeviceNotificationCallbackProcPtr
callback;
UInt32 refcon;
};
The USBInstallDeviceNotification function installs the device notification routine for the device specified in the USBDeviceNotificationParameterBlock . Pass in 0xffff or the wildcard constants as a wildcard for class, subclass, protocol, vendor, and/or product. Pass in kNotifyAnyEvent (0xff) in the usbDeviceNotification field to be notified for any change that occurs.
void USBInstallDeviceNotification(
USBDeviceNotificationParameterBlock *pb);
If a code fragment installs a device notification routine, the device notification routine must be removed with the USBRemoveDeviceNotification function before the code fragment is unloaded.
The USBRemoveDeviceNotification function removes a previously installed device notification routine.
OSStatus USBRemoveDeviceNotification (UInt32 token);
Previous | Back Up One Level | Next |